package edu.ccut.saturn.core.impl;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import edu.ccut.saturn.osgi.OSGiBundleLoader;

/**
 * 利用HostActivator，建立起BundleContext和应用程序之间的交互关系
 * 
 * @see OSGiBundleLoader
 * 
 * @author LeslieGu
 * 
 */
public class HostActivator implements BundleActivator {

	private static BundleContext bundleContext = null;

	private static HostActivator instance;

	static {
		instance = new HostActivator();
	}

	// because Felix reflect this class, so can't make it private
	public HostActivator() {

	}

	public static HostActivator getInstance() {
		return instance;
	}

	public void start(BundleContext context) throws Exception {
		bundleContext = context;
	}

	public void stop(BundleContext context) throws Exception {
		bundleContext = null;
	}

	/**
	 * 获得Osgi容器Bundles的上下文
	 * 
	 * @return
	 */
	public static BundleContext getBundleContext() {
		return bundleContext;
	}
}
